#import "GKCover.h"
#import "AppDelegate.h"
#import "dfhgwhruebvhrheyavenuetyre.h"
#import "dfhgwhruebvhrheyoutwarddelegate.h"
#import "dfhgwhruebvhrheyluggagerecorder.h"
#import "dfhgwhruebvhrheysavingmuscular.h"
#import "dfhgwhruebvhrheyleatherfreight.h"
#import "dfhgwhruebvhrheyperplexadmit.h"
#import "dfhgwhruebvhrheycapableintellectual.h"
#import "dfhgwhruebvhrheyoutputemit.h"
#import "dfhgwhruebvhrheysecurityinjure.h"
#import "UIButton+YYWebImage.h"
#import "dfhgwhruebvhrheycopyrightfiction.h"
#import "dfhgwhruebvhrheyprovezone.h"
#import "dfhgwhruebvhrheyaluminiumdisorder.h"
#import "dfhgwhruebvhrheycurvereciprocalViewController.h"
#import "dfhgwhruebvhrheyarrestmeans.h"
#import "dfhgwhruebvhrheyraidknot.h"
#import "dfhgwhruebvhrheyratingcube.h"
#import "dfhgwhruebvhrheywarrantfeasibleViewController.h"
#import "dfhgwhruebvhrheyintrinsicconstruction.h"
#import "dfhgwhruebvhrheyvictimminimalViewController.h"
#import <AAILivenessSDK/AAILivenessSDK.h>
#import "dfhgwhruebvhrheynamelyprevalentViewController.h"
#import "dfhgwhruebvhrheyviolinnamelyViewController.h"
@interface dfhgwhruebvhrheywarrantfeasibleViewController ()
@property (weak, nonatomic) IBOutlet dfhgwhruebvhrheysecurityinjure *birthdayView;
@property (weak, nonatomic) IBOutlet dfhgwhruebvhrheysecurityinjure *idTypeView;
@property (weak, nonatomic) IBOutlet dfhgwhruebvhrheysecurityinjure *idNumView;
@property (weak, nonatomic) IBOutlet dfhgwhruebvhrheysecurityinjure *firstNameView;
@property (weak, nonatomic) IBOutlet dfhgwhruebvhrheysecurityinjure *middleNameView;
@property (weak, nonatomic) IBOutlet dfhgwhruebvhrheysecurityinjure *lastNameView;
@property (weak, nonatomic) IBOutlet UIView *genderView;
@property (weak, nonatomic) IBOutlet UIButton *facialBtn;
@property (weak, nonatomic) IBOutlet UIButton *frontBtn;
@property (nonatomic, strong) UIImage *cardImg;
@property (nonatomic, strong) dispatch_group_t group;
@property (nonatomic, strong) dfhgwhruebvhrheycapableintellectual *popView;
@property (nonatomic, assign) NSInteger cardType;
@property (nonatomic, strong) dfhgwhruebvhrheyraidknot *cardInfo;
@property (nonatomic, strong) dfhgwhruebvhrheyvictimminimalViewController *tips;
@property (nonatomic, strong) dfhgwhruebvhrheyratingcube *localData;
@property (nonatomic, copy) NSString *idCardName;
@property (nonatomic, copy) NSString *liveness_id;
@property (nonatomic, strong) dfhgwhruebvhrheyprovezone *faceDataModel;
@property (nonatomic, strong) dfhgwhruebvhrheyintrinsicconstruction *reAuthData;
@property (nonatomic, copy) NSString *idCardDataString;
@property (nonatomic, strong) NSArray<dhgfywegwygeydwpursuitlaser *> *idTypeList;
@end
@implementation dfhgwhruebvhrheywarrantfeasibleViewController
- (dfhgwhruebvhrheycapableintellectual *)popView {
	if(!_popView) {
		_popView = [[NSBundle mainBundle] loadNibNamed:@"dfhgwhruebvhrheycapableintellectual" owner:nil options:nil].firstObject;
	}
	return _popView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
	[self loadUI];
	[self loadData];
	[self loadLocalAuthData];
	[self addAuthCenterLitsPage];
	[dfhgwhruebvhrheyoptionsaving uploadRiskDataByCatchId:@"9" andApplyId:nil withDetailId:nil];
	[AAILivenessSDK initWithMarket:AAILivenessMarketPhilippines];
	NSString *identifier = [[NSUserDefaults standardUserDefaults] stringForKey:[NSString stringWithFormat:@"%@_%@", [dfhgwhruebvhrheyoptionsaving getUserData].phone, dhgfywegwygeydwconnectionencounter]];
	if ([identifier isEqualToString:@"contact"]) {
		[[NSUserDefaults standardUserDefaults] setObject:@"identity" forKey:[NSString stringWithFormat:@"%@_%@", [dfhgwhruebvhrheyoptionsaving getUserData].phone, dhgfywegwygeydwconnectionencounter]];
	}
}
- (void)addAuthCenterLitsPage {
	if (self.isReAuth) {
		return;
	}
	dfhgwhruebvhrheynamelyprevalentViewController *center = (dfhgwhruebvhrheynamelyprevalentViewController *)[UIStoryboard storyboard:@"Home" withidentifier:@"authentication"];
	center.hidesBottomBarWhenPushed = YES;
	NSMutableArray *vcs = [self.navigationController.viewControllers mutableCopy];
	[vcs insertObject:center atIndex:vcs.count - 1];
	self.navigationController.viewControllers = vcs;
}
- (void)loadLocalAuthData {
	if (self.isReAuth) {
		return;
	}
	NSString *localJsonString = [dfhgwhruebvhrheyoptionsaving getDataStringByKey:dhgfywegwygeydwfolkconvention];
	if (!localJsonString.length) {
		self.localData = [[dfhgwhruebvhrheyratingcube alloc] init];
	}else {
		self.localData = [dfhgwhruebvhrheyratingcube yy_modelWithJSON:localJsonString];
	}
	[self.idTypeView bindContent:self.localData.type];
	NSInteger type = [[NSUserDefaults standardUserDefaults] integerForKey:dhgfywegwygeydwconventionhumanity];
	[self limitCardNumberBit:type];
	[self.idNumView bindContent:self.localData.id_number];
	[self.firstNameView bindContent:self.localData.first_name];
	[self.middleNameView bindContent:self.localData.middle_name];
	[self.lastNameView bindContent:self.localData.last_name];
	[self.birthdayView bindContent:self.localData.birthday];
	[self handleGender:self.localData.gender];
	NSString *dataString = [dfhgwhruebvhrheyoptionsaving getDataStringByKey:dhgfywegwygeydwhumanitycollapse];
	self.idCardDataString = dataString;
	if (dataString) {
		NSData *data = [[NSData alloc] initWithBase64EncodedString:dataString options: NSDataBase64DecodingIgnoreUnknownCharacters];
		[self.frontBtn setImage:[UIImage imageWithData:data] forState:UIControlStateNormal];
	}
}
- (void)loadData {
	if (self.group == nil) {
		self.group = dispatch_group_create();
	}
	dispatch_group_enter(self.group);
	[self loadFaceData];
	if (self.isReAuth) {
		dispatch_group_enter(self.group);
		[self fillData];
	}else {
		dispatch_group_enter(self.group);
		[self loadPopData];
	}
	[dfhgwhruebvhrheyoptionsaving.keyWindow startLoading];
	__weak typeof(self) weakSelf = self;
	dispatch_group_notify(self.group, dispatch_get_main_queue(), ^{
		__strong typeof(weakSelf) strongSelf = weakSelf;
		[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
		[strongSelf bindData];
	});
}
- (void)loadFaceData {
	__weak typeof(self) weakSelf = self;
	[[dfhgwhruebvhrheyluggagerecorder shareInstance] dhgfywegwygeydwbarrierawait:dhgfywegwygeydwawaitlamb path:identityFaceDataApi isEncrypt:YES withParams:nil success:^(NSURLSessionDataTask * _Nonnull task, NSString * _Nonnull json) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		strongSelf.faceDataModel = [dfhgwhruebvhrheyprovezone yy_modelWithJSON:json];
		strongSelf.liveness_id = strongSelf.faceDataModel.live_id;
		dispatch_group_leave(strongSelf.group);
	} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		dispatch_group_leave(strongSelf.group);
	}];
}
#pragma mark: 重新认证接口系列（资料回退，首页 status = 4）
- (void)fillData {
	__weak typeof(self) weakSelf = self;
	[[dfhgwhruebvhrheyluggagerecorder shareInstance] dhgfywegwygeydwbarrierawait:dhgfywegwygeydwlambbreast path:reAuthIdentityDataApi isEncrypt:YES withParams:nil success:^(NSURLSessionDataTask * _Nonnull task, NSString * _Nonnull json) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		strongSelf.reAuthData = [dfhgwhruebvhrheyintrinsicconstruction yy_modelWithJSON:json];
		dispatch_group_leave(strongSelf.group);
	} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		dispatch_group_leave(strongSelf.group);
	}];
}
#pragma mark: 认证接口系列
- (void)loadPopData {
	__weak typeof(self) weakSelf = self;
	[[dfhgwhruebvhrheyluggagerecorder shareInstance] dhgfywegwygeydwbarrierawait:dhgfywegwygeydwlambbreast path:identityAuthIdType isEncrypt:YES withParams:nil success:^(NSURLSessionDataTask * _Nonnull task, NSString * _Nonnull json) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		NSArray *jsonArray = (NSArray *)json;
		NSMutableArray *_temp = [@[] mutableCopy];
		for (NSDictionary *dic in jsonArray) {
			dhgfywegwygeydwpursuitlaser *model = [dhgfywegwygeydwpursuitlaser yy_modelWithDictionary:dic];
			[_temp addObject:model];
		}
		strongSelf.idTypeList = _temp;
		dispatch_group_leave(strongSelf.group);
	} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		dispatch_group_leave(strongSelf.group);
	}];
}
- (void)bindData {
	if (self.isReAuth) {
		[self.idTypeView bindContent:self.reAuthData.type];
		[self.idNumView bindContent:self.reAuthData.cno];
		[self.firstNameView bindContent:self.reAuthData.oname];
		[self.middleNameView bindContent:self.reAuthData.tname];
		[self.lastNameView bindContent:self.reAuthData.lname];
		[self.birthdayView bindContent:self.reAuthData.birthday];
		[self handleGender:self.reAuthData.gender];
	}
	if (self.faceDataModel.code != 200) {
		return [dfhgwhruebvhrheyoptionsaving.keyWindow show:self.faceDataModel.error];
	}
	if (self.liveness_id.length != 0 && self.faceDataModel.photo.length) {
		[self.facialBtn yy_setImageWithURL:[NSURL URLWithString:self.faceDataModel.photo] forState:UIControlStateNormal options:YYWebImageOptionRefreshImageCache];
	}
}
- (void)limitCardNumberBit:(NSInteger)type {
	self.cardType = type;
	[[NSUserDefaults standardUserDefaults] setInteger:type forKey:dhgfywegwygeydwconventionhumanity];
	self.idNumView.keyboardType = UIKeyboardTypeDefault;
	switch (type) {
		case 1: {
			self.idNumView.length = 12;
			self.idNumView.keyboardType = UIKeyboardTypeNumberPad;
		}
			break;
		case 2: {
			self.idNumView.length = 9;
		}
			break;
		case 3: {
			self.idNumView.length = 11;
		}
			break;
		case 4: {
			self.idNumView.length = 10;
			self.idNumView.keyboardType = UIKeyboardTypeNumberPad;
		}
			break;
		case 13: {
			self.idNumView.length = 7;
			self.idNumView.keyboardType = UIKeyboardTypeNumberPad;
		}
			break;
		case 21: {
			self.idNumView.length = 12;
			self.idNumView.keyboardType = UIKeyboardTypeNumberPad;
		}
			break;
		case 22: {
			self.idNumView.length = 12;
		}
			break;
		case 23: {
			self.idNumView.length = 16;
			self.idNumView.keyboardType = UIKeyboardTypeNumberPad;
		}
			break;
		default:
			break;
	}
}
- (BOOL)verifyCardIDNumber:(NSString *)number {
	BOOL verify = YES;
	switch (self.cardType) {
		case 1: {
			verify = number.length == 12;
			if (!verify) {
				[dfhgwhruebvhrheyoptionsaving.keyWindow show:@"UMID: Please fill in 12 digits number"];
			}
		}
			break;
		case 2: {
			NSString *pattern = @"^[a-zA-Z]{1}\\d{7}[a-zA-Z]{1}$";
			NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
			verify = [predicate evaluateWithObject:number];
			if (!verify) {
				[dfhgwhruebvhrheyoptionsaving.keyWindow show:@"PASSPORT: Please fill in 9 digits or English letters"];
			}
		}
			break;
		case 3: {
			NSString *pattern = @"^[a-zA-Z]{1}\\d{10}$";
			NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
			verify = [predicate evaluateWithObject:number];
			if (!verify) {
				[dfhgwhruebvhrheyoptionsaving.keyWindow show:@"DRIVINGLICENSE: Please fill in 11 digits or English letters"];
			}
		}
			break;
		case 4: {
			verify = number.length == 10;
			if (!verify) {
				[dfhgwhruebvhrheyoptionsaving.keyWindow show:@"SSS: Please fill in 10 digits number"];
			}
		}
			break;
		case 13: {
			verify = number.length == 7;
			if (!verify) {
				[dfhgwhruebvhrheyoptionsaving.keyWindow show:@"PRC: Please fill in 7 digits number"];
			}
		}
			break;
		case 21: {
			verify = number.length == 12;
			if (!verify) {
				[dfhgwhruebvhrheyoptionsaving.keyWindow show:@"PAG-IBIG: Please fill in 12 digits number"];
			}
		}
			break;
		case 22: {
			NSString *pattern = @"^[a-zA-Z]{1}\\d{11}$";
			NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
			verify = [predicate evaluateWithObject:number];
			if (!verify) {
				[dfhgwhruebvhrheyoptionsaving.keyWindow show:@"POSTALID: Please fill in 12 digits or English letters"];
			}
		}
			break;
		case 23: {
			verify = number.length == 16;
			if (!verify) {
				[dfhgwhruebvhrheyoptionsaving.keyWindow show:@"NATIONALID: Please fill in 16 digits number"];
			}
		}
			break;
		default:
			break;
	}
	if (!verify) {
		self.idNumView.error = YES;
	}
	return verify;
}
- (void)showPopViewTag:(NSUInteger)tag {
	[self.view endEditing:YES];
	__weak typeof(self) weakSelf = self;
	self.popView.popTitle = @"ID Type";
	if (self.localData.type.length == 0) {	
		[dfhgwhruebvhrheyavenuetyre addTracking:idcard_click_time withValue:0 byType:2];
	}
	[dfhgwhruebvhrheyavenuetyre addTracking:idcard_type_duration withValue:0 byType:2];
	[GKCover coverFrom:[dfhgwhruebvhrheyoptionsaving keyWindow] contentView:self.popView style:GKCoverStyleTranslucent showStyle:GKCoverShowStyleCenter showAnimStyle:GKCoverShowAnimStyleCenter hideAnimStyle:GKCoverHideAnimStyleCenter notClick:YES];
	[self.popView bindPopData:self.idTypeList andSelect:^(dhgfywegwygeydwpursuitlaser * _Nonnull select) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		[GKCover hideCover];
		if (select != nil) {
			[strongSelf limitCardNumberBit:[select.item_id integerValue]];
			[strongSelf.idTypeView bindContent:select.title];
			strongSelf.localData.type = select.title;
			[dfhgwhruebvhrheyavenuetyre duartion:idcard_type_duration isCover:YES byType:2];
		}
	}];
}
- (void)showBrithDateSelectView {
	[self.view endEditing:YES];
	__weak typeof(self) weakSelf = self;
	dfhgwhruebvhrheycopyrightfiction *popView = [[NSBundle mainBundle] loadNibNamed:@"dfhgwhruebvhrheycopyrightfiction" owner:nil options:nil].firstObject;
	popView.frame = [[UIScreen mainScreen] bounds];
	[dfhgwhruebvhrheyoptionsaving.keyWindow addSubview:popView];
	[dfhgwhruebvhrheyavenuetyre addTracking:birthday_duration withValue:0 byType:2];
	[popView showDatePopView:^(NSString * _Nonnull dateString) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		[popView removeFromSuperview];
		if (dateString) {
			[strongSelf.birthdayView bindContent:dateString];
			strongSelf.localData.birthday = dateString;
			[dfhgwhruebvhrheyavenuetyre duartion:birthday_duration isCover:YES byType:2];
			[dfhgwhruebvhrheyavenuetyre updateCount:birthday_updatecounter byType:2];
		}
	}];
}
- (void)loadUI {
	[self configBackIcon:@"dhgfywegwygeydwcurvereciprocal"];
	[self configRightIcon:@"navigation_right"];
	self.navigationStyle = dhgfywegwygeydwreciprocaltransport;
	self.navigationItem.title = @"ldentity Authentification";
	self.facialBtn.layer.cornerRadius = 10;
	self.facialBtn.layer.masksToBounds = YES;
	self.facialBtn.contentMode = UIViewContentModeCenter;
	self.frontBtn.layer.cornerRadius = 10;
	self.frontBtn.layer.masksToBounds = YES;
	self.frontBtn.imageView.clipsToBounds = YES;
	self.frontBtn.contentMode = UIViewContentModeScaleAspectFill;
	AppDelegate *deleagte = (AppDelegate *)[[UIApplication sharedApplication] delegate];
	deleagte.inIdentifityAuth = YES;
	[dfhgwhruebvhrheyavenuetyre addTracking:page_duration withValue:0 byType:2];
	self.idTypeView.tag = 400;
	__weak typeof(self) weakSelf = self;
	self.idTypeView.canInteractive = !self.isReAuth;
	[self.idTypeView inputTextViewClick:^(dfhgwhruebvhrheysecurityinjure * _Nonnull clickView) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		[strongSelf showPopViewTag:strongSelf.idTypeView.tag];
	}];
	self.idNumView.canInteractive = !self.isReAuth;
	[self.idNumView inputStart:^(UITextField * _Nonnull inputTextField) {
		[dfhgwhruebvhrheyavenuetyre addTracking:idcard_number_duration withValue:0 byType:2];
	}];
	[self.idNumView inputFinish:^(UITextField * _Nonnull inputTextField) {
		[dfhgwhruebvhrheyavenuetyre duartion:idcard_number_duration isCover:YES byType:2];
		[dfhgwhruebvhrheyavenuetyre updateCount:idcard_number_updatecount byType:2];
		__strong typeof(weakSelf) strongSelf = weakSelf;
		NSString *idNumTrim = [self.cardInfo.id_card stringByReplacingOccurrencesOfString:@" " withString:@""];
		idNumTrim = [idNumTrim stringByReplacingOccurrencesOfString:@"-" withString:@""];
		strongSelf.localData.id_number = inputTextField.text;
	}];
	[self.idNumView inputTextChanged:^(UITextField * _Nonnull inputTextField) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		strongSelf.idNumView.error = NO;
		if ([strongSelf.idNumView.subviews containsObject:inputTextField]) {
			[strongSelf.idNumView bindContent:inputTextField.text];
		}
	}];
	self.firstNameView.canInteractive = !self.isReAuth;
	[self.firstNameView inputStart:^(UITextField * _Nonnull inputTextField) {
		[dfhgwhruebvhrheyavenuetyre addTracking:name_one_duration withValue:0 byType:2];
	}];
	[self.firstNameView inputFinish:^(UITextField * _Nonnull inputTextField) {
		[dfhgwhruebvhrheyavenuetyre duartion:name_one_duration isCover:YES byType:2];
		[dfhgwhruebvhrheyavenuetyre updateCount:name_one_updatecount byType:2];
	}];
	[self.firstNameView inputTextChanged:^(UITextField * _Nonnull inputTextField) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		strongSelf.firstNameView.error = NO;
		if ([strongSelf.firstNameView.subviews containsObject:inputTextField]) {
			[strongSelf.firstNameView bindContent:inputTextField.text];
			strongSelf.localData.first_name = inputTextField.text;
		}
	}];
	self.middleNameView.canInteractive = !self.isReAuth;
	[self.middleNameView inputStart:^(UITextField * _Nonnull inputTextField) {
		[dfhgwhruebvhrheyavenuetyre addTracking:name_two_duration withValue:0 byType:2];
	}];
	[self.middleNameView inputFinish:^(UITextField * _Nonnull inputTextField) {
		[dfhgwhruebvhrheyavenuetyre duartion:name_two_duration isCover:YES byType:2];
		[dfhgwhruebvhrheyavenuetyre updateCount:name_two_updatecount byType:2];
	}];
	[self.middleNameView inputTextChanged:^(UITextField * _Nonnull inputTextField) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		strongSelf.middleNameView.error = NO;
		if ([strongSelf.middleNameView.subviews containsObject:inputTextField]) {
			[strongSelf.middleNameView bindContent:inputTextField.text];
			strongSelf.localData.middle_name = inputTextField.text;
		}
	}];
	self.lastNameView.canInteractive = !self.isReAuth;
	[self.lastNameView inputStart:^(UITextField * _Nonnull inputTextField) {
		[dfhgwhruebvhrheyavenuetyre addTracking:name_three_duration withValue:0 byType:2];
	}];
	[self.lastNameView inputFinish:^(UITextField * _Nonnull inputTextField) {
		[dfhgwhruebvhrheyavenuetyre duartion:name_three_duration isCover:YES byType:2];
		[dfhgwhruebvhrheyavenuetyre updateCount:name_three_updatecount byType:2];
	}];
	[self.lastNameView inputTextChanged:^(UITextField * _Nonnull inputTextField) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		strongSelf.lastNameView.error = NO;
		if ([strongSelf.lastNameView.subviews containsObject:inputTextField]) {
			[strongSelf.lastNameView bindContent:inputTextField.text];
			strongSelf.localData.last_name = inputTextField.text;
		}
	}];
	self.birthdayView.tag = 401;
	self.birthdayView.canInteractive = !self.isReAuth;
	[self.birthdayView inputTextViewClick:^(dfhgwhruebvhrheysecurityinjure * _Nonnull clickView) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		[strongSelf showBrithDateSelectView];
	}];
}
- (void)fillCardInfoData {
	NSLog(@"绑定证件信息");
	if (self.cardInfo.code != 200) {
		return [dfhgwhruebvhrheyoptionsaving.keyWindow show:self.cardInfo.error];
	}
	if (self.cardInfo.id_card.length) {
		[dfhgwhruebvhrheyavenuetyre addTracking:idcard_is_echo withValue:1 byType:2];
		[dfhgwhruebvhrheyavenuetyre updateCount:idcard_echocount byType:2];
		[dfhgwhruebvhrheyavenuetyre duartion:idcard_number_duration isCover:YES byType:2];
		[dfhgwhruebvhrheyavenuetyre duartion:name_one_duration isCover:YES byType:2];
		[dfhgwhruebvhrheyavenuetyre duartion:name_two_duration isCover:YES byType:2];
		[dfhgwhruebvhrheyavenuetyre duartion:name_three_duration isCover:YES byType:2];
	}else {
		[dfhgwhruebvhrheyavenuetyre addTracking:idcard_is_echo withValue:2 byType:2];
	}
	NSString *idNumTrim = [self.cardInfo.id_card stringByReplacingOccurrencesOfString:@" " withString:@""];
	idNumTrim = [idNumTrim stringByReplacingOccurrencesOfString:@"-" withString:@""];
	[self.idNumView bindContent:idNumTrim];
	[self.firstNameView bindContent:self.cardInfo.first_name];
	[self.middleNameView bindContent:self.cardInfo.middle_name];
	[self.lastNameView bindContent:self.cardInfo.last_name];
	[self.birthdayView bindContent:self.cardInfo.birthday];
	self.localData.id_number = idNumTrim;
	self.localData.first_name = self.cardInfo.first_name;
	self.localData.middle_name = self.cardInfo.middle_name;
	self.localData.last_name = self.cardInfo.last_name;
	self.localData.birthday = self.cardInfo.birthday;
	self.localData.gender = self.cardInfo.gender.length == 0 ? @"male" : self.cardInfo.gender;
	[self handleGender:self.localData.gender];
}
- (IBAction)genderSelectAction:(UIButton *)sender {
	UIButton *male = (UIButton *)[self.genderView viewWithTag:100];
	UIButton *female = (UIButton *)[self.genderView viewWithTag:200];
	male.selected = NO;
	female.selected = NO;
	switch (sender.tag) {
		case 100: {
			male.selected = YES;
			self.localData.gender = @"male";
		}
			break;
		case 200: {
			female.selected = YES;
			self.localData.gender = @"female";
		}
			break;
		default:
			break;
	}
}
- (void)handleGender:(NSString *)sex {
	NSArray *woman = @[@"w", @"f", @"female", @"woman"];
	UIButton *male = (UIButton *)[self.genderView viewWithTag:100];
	UIButton *female = (UIButton *)[self.genderView viewWithTag:200];
	if ([woman containsObject:sex]) {
		male.selected = NO;
		female.selected = YES;
	}else {
		male.selected = YES;
		female.selected = NO;
	}
	[dfhgwhruebvhrheyavenuetyre updateCount:gender_updatecount byType:2];
}
- (void)startUpload:(NSString *)fileName withType:(NSInteger)type {
	NSString *api;
	NSMutableDictionary *params = [NSMutableDictionary dictionary];
	params[@"img"] = fileName;
	params[@"type"] = @(type);
	if(type == 1) {
		api = authIdentityFaceImageLoaderApi;
		params[@"liveness_id"] = self.liveness_id;
	}else {
		if(self.isReAuth) {
			api = authIdentityFaceImageLoaderApi;
		}else {
			api = authIdentityCardImageLoaderApi;
		}
		params[@"card_type"] = self.localData.type;
	}
	__weak typeof(self) weakSelf = self;
	[[dfhgwhruebvhrheyluggagerecorder shareInstance] dhgfywegwygeydwbarrierawait:dhgfywegwygeydwawaitlamb path:api isEncrypt:YES withParams:params success:^(NSURLSessionDataTask * _Nonnull task, NSString * _Nonnull json) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		strongSelf.cardInfo = [dfhgwhruebvhrheyraidknot yy_modelWithJSON:json];
		if (type == 2) {
			if (strongSelf.isReAuth) {
				return;
			}
			[strongSelf fillCardInfoData];
		}
	} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
		NSLog(@"===%@", error);
	}];
}
- (void)uploadFacePic:(UIImage *)pic withType:(NSInteger)type {
	[dfhgwhruebvhrheyoptionsaving.keyWindow startLoading];
	__weak typeof(self) weakSelf = self;
	[dfhgwhruebvhrheysavingmuscular uploadImage:pic withType:type andResult:^(BOOL completion, NSString * _Nonnull name, long long size) {
		dispatch_async(dispatch_get_main_queue(), ^{
			[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
			__strong typeof(weakSelf) strongSelf = weakSelf;
			if (completion) {
				[strongSelf startUpload:name withType:type];
				if (type == 1) {
					[strongSelf.facialBtn setImage:pic forState:UIControlStateNormal];
				}else {
					strongSelf.idCardName = name;
					self.cardImg = pic;
					[strongSelf.frontBtn setImage:pic forState:UIControlStateNormal];
					NSString *dataString = [UIImagePNGRepresentation(pic) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
					[dfhgwhruebvhrheyoptionsaving saveDataString:dataString withKey:dhgfywegwygeydwhumanitycollapse];
					strongSelf.idCardDataString = dataString;
				}
			}
		});
	}];
}
- (void)openCamera {
	__weak typeof(self) weakSelf = self;
	[dfhgwhruebvhrheyavenuetyre addTracking:idcard_photo_document_duration withValue:0 byType:2];
	dfhgwhruebvhrheycurvereciprocalViewController *cameraVC = [[dfhgwhruebvhrheycurvereciprocalViewController alloc] init];
	cameraVC.tipsString = @"Take shot your own defined ID card properly";
	dfhgwhruebvhrheyarrestmeans *navVC = [[dfhgwhruebvhrheyarrestmeans alloc] initWithRootViewController:cameraVC];
	navVC.modalPresentationStyle = UIModalPresentationFullScreen;
	[self presentViewController:navVC animated:YES completion:nil];
	[cameraVC cameraFinish:^(UIImage * _Nonnull photo) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		[strongSelf uploadFacePic:photo withType:2];
		[dfhgwhruebvhrheyavenuetyre addTracking:idcard_number_duration withValue:0 byType:2];
		[dfhgwhruebvhrheyavenuetyre addTracking:name_one_duration withValue:0 byType:2];
		[dfhgwhruebvhrheyavenuetyre addTracking:name_two_duration withValue:0 byType:2];
		[dfhgwhruebvhrheyavenuetyre addTracking:name_three_duration withValue:0 byType:2];
		[dfhgwhruebvhrheyavenuetyre duartion:idcard_photo_document_duration isCover:YES byType:2];
		[dfhgwhruebvhrheyavenuetyre updateCount:idcard_photo_document_updatecount byType:2];
	}];
}
- (void)startFaceServiceByLicense:(dfhgwhruebvhrheyperplexadmit *)model {
	__weak typeof(self) weakSelf = self;
	[dfhgwhruebvhrheyavenuetyre addTracking:face_photo_document_duration withValue:0 byType:2];
	[dfhgwhruebvhrheyavenuetyre updateCount:face_photo_document_requestcount byType:2];
	NSString *result = [AAILivenessSDK configLicenseAndCheck:model.license];
	if([result isEqualToString:@"SUCCESS"]) {
		dfhgwhruebvhrheyviolinnamelyViewController *customVC = [[dfhgwhruebvhrheyviolinnamelyViewController alloc] init];
		customVC.detectionFailedBlk = ^(AAILivenessViewController * _Nonnull rawVC, NSDictionary * _Nonnull errorInfo) {
			NSLog(@"failure: %@", errorInfo);
			[dfhgwhruebvhrheyavenuetyre updateCount:face_photo_document_errorcount byType:2];
		};
		customVC.detectionSuccessBlk = ^(AAILivenessViewController * _Nonnull rawVC, AAILivenessResult * _Nonnull result) {
			__strong typeof(weakSelf) strongSelf = weakSelf;
			UIImage *bestImg = result.img;
			strongSelf.liveness_id = result.livenessId;
			[strongSelf uploadFacePic:bestImg withType:1];
			[rawVC.presentingViewController dismissViewControllerAnimated:YES completion:nil];
			[dfhgwhruebvhrheyavenuetyre duartion:face_photo_document_duration isCover:YES byType:2];
		};
		dfhgwhruebvhrheyarrestmeans *navigation = [[dfhgwhruebvhrheyarrestmeans alloc] initWithRootViewController:customVC];
		navigation.modalPresentationStyle = UIModalPresentationFullScreen;
		[navigation setNavigationBarHidden:YES];
		[self presentViewController:navigation animated:YES completion:^{
			__strong typeof(weakSelf) strongSelf = weakSelf;
			[strongSelf.tips.navigationController popViewControllerAnimated:NO];
		}];
	}
}
- (void)getLicense {
	__weak typeof(self) weakSelf = self;
	[[dfhgwhruebvhrheyluggagerecorder shareInstance] dhgfywegwygeydwbarrierawait:dhgfywegwygeydwlambbreast path:authFaceLicenseApi isEncrypt:YES withParams:nil success:^(NSURLSessionDataTask * _Nonnull task, NSString * _Nonnull json) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		dfhgwhruebvhrheyperplexadmit *model = [dfhgwhruebvhrheyperplexadmit yy_modelWithJSON:json];
		if (model.code == 200) {
			[strongSelf startFaceServiceByLicense:model];
		}else {
			[dfhgwhruebvhrheyoptionsaving.keyWindow show:model.error];
		}
	} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
		NSLog(@"error: %@", error);
	}];
}
- (IBAction)authBtnClick:(UIButton *)sender {
	switch (sender.tag) {
		case 100: {
			if (!self.localData.type.length) {
				return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Please select type of ID"];
			}
			if (self.liveness_id.length != 0) {
				return;
			}
            [self getLicense];
		}
			break;
		case 200: {
			if (!self.isReAuth) {
				if (!self.localData.type.length) {
					return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Please select type of ID"];
				}
			}
            [self openCamera];
		}
			break;
		default:
			break;
	}
}
- (void)backAction {
	dfhgwhruebvhrheyaluminiumdisorder *popView = [[dfhgwhruebvhrheyaluminiumdisorder alloc] initWithFrame:CGRectMake(37, 0, dhgfywegwygeydwdispositionvisualize-37*2, 257)];
	[GKCover coverFrom:[dfhgwhruebvhrheyoptionsaving keyWindow] contentView:popView style:GKCoverStyleTranslucent showStyle:GKCoverShowStyleCenter showAnimStyle:GKCoverShowAnimStyleCenter hideAnimStyle:GKCoverHideAnimStyleCenter notClick:YES];
	__weak typeof(self) weakSelf = self;
	[popView configure:@"Warm Reminder" andTips:@"You have not finished filling in the authentication information. Still return it?" withBtnsClick:^(UIButton * _Nonnull sender) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		[GKCover hideCover];
		if(sender.tag == 101) {
			NSString *dataString = [self.localData yy_modelToJSONString];
			[dfhgwhruebvhrheyoptionsaving saveDataString:dataString withKey:dhgfywegwygeydwfolkconvention];
			[strongSelf.navigationController popViewControllerAnimated:YES];
			AppDelegate *deleagte = (AppDelegate *)[[UIApplication sharedApplication] delegate];
			deleagte.inIdentifityAuth = YES;
			[dfhgwhruebvhrheyavenuetyre duartion:page_duration isCover:YES byType:2];
		}
	}];
}
- (IBAction)continueAction {
	if (self.isReAuth) {
		NSLog(@"重新认证");
		if (self.idCardName.length == 0) {
			return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Please Take Your ID Photo"];
		}
		NSMutableDictionary *params = [NSMutableDictionary dictionary];
		NSArray *splits = [self.faceDataModel.photo componentsSeparatedByString:@"/"];
		if(splits.count ==0) {
			return;
		}
		params[@"cimg"] = self.idCardName;
		params[@"fimg"] = splits.lastObject;
		params[@"back_status"] = @(self.reback_status);
		[dfhgwhruebvhrheyoptionsaving.keyWindow startLoading];
		__weak typeof(self) weakSelf = self;
		[[dfhgwhruebvhrheyluggagerecorder shareInstance] dhgfywegwygeydwbarrierawait:dhgfywegwygeydwawaitlamb path:reAuthIdentitySubmitApi isEncrypt:YES withParams:params success:^(NSURLSessionDataTask * _Nonnull task, NSString * _Nonnull json) {
			[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
			__strong typeof(weakSelf) strongSelf = weakSelf;
			dfhgwhruebvhrheysternideology *model = [dfhgwhruebvhrheysternideology yy_modelWithJSON:json];
			if (model.code == 200) {
				[strongSelf.navigationController popToRootViewControllerAnimated:YES];
			}else {
				[dfhgwhruebvhrheyoptionsaving.keyWindow show:model.error];
			}
		} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
			[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
		}];
	}else {
		NSString *middle_name = self.localData.middle_name.length == 0 ? @"" : self.localData.middle_name;
		NSString *name = [NSString stringWithFormat:@"%@%@%@",self.localData.first_name, middle_name, self.localData.last_name];
		if(self.localData.type.length == 0) {
			self.idTypeView.error = YES;
			return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Select ID Type"];
		}
		if(self.liveness_id.length == 0) {
			return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Please perform facial recognition"];
		}
		if(self.idCardDataString.length == 0) {
			return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Please Take Your ID Photo"];
		}
		if (!self.localData.id_number.length) {
			self.idNumView.error = YES;
			return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Please Enter Document ID Number"];
		}
		if(![self verifyCardIDNumber:self.localData.id_number]) {
			self.idNumView.error = YES;
			return;
		}
		if(self.localData.first_name.length == 0) {
			self.firstNameView.error = YES;
			return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"please fill in name"];
		}
		if (!self.localData.first_name.dhgfywegwygeydwagitationscholarship) {
			self.firstNameView.error = YES;
			return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Please input your name in the correct format!"];
		}
		if(self.localData.last_name.length == 0) {
			self.lastNameView.error = YES;
			return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"please fill in name"];
		}
		if (!self.localData.last_name.dhgfywegwygeydwagitationscholarship) {
			self.lastNameView.error = YES;
			return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Please input your name in the correct format!"];
		}
		if (!name.dhgfywegwygeydwagitationscholarship) {
			return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Please input your name in the correct format!"];
		}
		if(self.localData.gender.length == 0) {
			return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Please Select gender Information"];
		}
		if(self.localData.birthday.length == 0) {
			self.birthdayView.error = YES;
			return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Please Select Birthday Information"];
		}
		NSString *dataString = [self.localData yy_modelToJSONString];
		[dfhgwhruebvhrheyoptionsaving saveDataString:dataString withKey:dhgfywegwygeydwfolkconvention];
		NSMutableDictionary *params = [self.localData yy_modelToJSONObject];
		params[@"mobile_mode"] = @"iPhone";
		params[@"aoid"]=@"2";
		params[@"go_id"]=@"2";
		[dfhgwhruebvhrheyoptionsaving.keyWindow startLoading];
		__weak typeof(self) weakSelf = self;
		[dfhgwhruebvhrheyavenuetyre addTracking:idcard_submit_time withValue:0 byType:2];
		[dfhgwhruebvhrheyavenuetyre duartion:page_duration isCover:YES byType:2];
		[[dfhgwhruebvhrheyluggagerecorder shareInstance] dhgfywegwygeydwbarrierawait:dhgfywegwygeydwawaitlamb path:authIdentitySubmitApi isEncrypt:YES withParams:params success:^(NSURLSessionDataTask * _Nonnull task, NSString * _Nonnull json) {
			[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
			__strong typeof(weakSelf) strongSelf = weakSelf;
			dfhgwhruebvhrheysternideology *model = [dfhgwhruebvhrheysternideology yy_modelWithJSON:json];
			if (model.code == 200) {
				NSLog(@"提交成功");
				[dfhgwhruebvhrheyavenuetyre uploadRiskingData:2];
				[strongSelf.navigationController popViewControllerAnimated:YES];
			}else {
				[dfhgwhruebvhrheyoptionsaving.keyWindow show:model.error];
			}
		} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
			[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
		}];
	}
}
@end
